home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / gnu_st.lha / gnu_st / smalltalk-1.1.1 / Autoload.st < prev    next >
Text File  |  1991-09-12  |  1KB  |  43 lines

  1. Object subclass: #Autoload
  2.        instanceVariableNames: 'className fileName'
  3.        classVariableNames: ''
  4.        poolDictionaries: ''
  5.        category: 'Cool hacks' !
  6.  
  7. Autoload comment:
  8. 'I am not a part of the normal Smalltalk kernel class system.  I provide the
  9. ability to do late-loading or "on demand loading" of class definitions.
  10. Through me, you can define any class to be loaded when any message is sent to
  11. the class itself (such as to create an instance).' !
  12.  
  13. !Autoload class methodsFor: 'instance creation'!
  14.  
  15. class: classNameString from: fileNameString
  16.     ^Autoload new autoloadInitClass: classNameString 
  17.           initFile: fileNameString
  18. !!
  19.  
  20.  
  21. !Autoload methodsFor: 'accessing'!
  22.  
  23. doesNotUnderstand: aMessage
  24.     | s |
  25.     Smalltalk removeKey: className.
  26.     FileStream fileIn: fileName.
  27.     ^aMessage reinvokeFor: (Smalltalk at: className
  28.                       ifAbsent: [ ^Autoload error: 
  29. 'Autoloaded file should have defined class "', className, '" but didn''t' ])
  30. !!
  31.  
  32.  
  33.  
  34. !Autoload methodsFor: 'private'!
  35.  
  36. autoloadInitClass: aClassName initFile: aFileName
  37.     className _ aClassName asSymbol.
  38.     Smalltalk at: className put: self.
  39.     fileName _ aFileName.
  40. !!
  41.  
  42. Autoload superclass: nil!    "force undefined methods"
  43.